<template>
	<view class="content">
		<my-home class="home-float" v-if="floatData.open == 1" :floatData="floatData" :floatX="floatX" :floatY="floatY" :floatFrom="22"></my-home>
		<view class="list">
			<view class="item" v-for="(item,i) in list" :key="i" @click="handleListClick(i)">
				<image class="list-image" mode="widthFix" :src="item.imgUrl"></image>
			</view>
		</view>
		<no-data  v-if="list && list.length==0" :src="noDataSrc" :txt="noDataTxt"></no-data>
		
		<view class="bottom-safe-area"></view>
		<!--单悬浮客服-->
		<common-drag />
	</view>
</template>
<script>
	export default {
		data() {
			return {
				//list
				//no-data
				noDataSrc:this.$noData,
				noDataTxt:'暂无特惠套餐',
				list:'',
				from:'',
				floatData:{} ,
				floatX:340,
				floatY:50,
				clientHeight:null,
			}
		},
		onLoad(options) {
			if(options.from){
				this.from=options.from;
			}
			this.getListRequest();
			this.getClineHeight();
		},
		methods: {
			getBarHeight(){
			        const res = uni.getSystemInfoSync()
			        if(res.platform==='ios'){
			            return 44+res.statusBarHeight
			        }else if(res.platform==='android'){
			            return 48+res.statusBarHeight
			        }else{
			            return 0;
			        }
			    },
			    //获取可视区域高度
			    getClineHeight(){
			        const res = uni.getSystemInfo({
			            success:(res=>{
			                this.clientHeight = res.windowHeight-uni.upx2px(80)-this.getBarHeight();
							this.floatY =  this.clientHeight - 50;
			            })
			        });
			    },
			//request
			getListRequest(){
				this.$u.api.getComboList().then(res=>{
					if(res.result_code=='300'){
						this.floatData = res.data.window;
						let arr=res.data.list;
						let len=arr.length;
						let list=[];
						for(let i=0;i<len;i++){
							let json={};
							json.imgUrl=arr[i].img;
							json.isJoin=arr[i].is_join;//1 未参与 2 已参与
							json.url=arr[i].url;
							json.type=arr[i].url_type;//2 会员 3 月卡 4 购车 5电池换购
							list.push(json);
						};
						this.list=list;
					}else{
						this.$utils.toast(res.msg);
					};
				}).catch(()=>{

				});
			},
			
			handleListClick(i){
				//Check if you want to jump to the webview
				if(this.list[i].url){
					this.$utils.jumpWebview(this.list[i].url)					
				}else{
					//Check whether it is a monthly card or a membership card
					if(this.list[i].type=="2"){
						//member card
						uni.navigateTo({
						    url:'/pages/pay/member-recharge?from='+this.from
						});
					}else if(this.list[i].type=="3"){
						
						uni.navigateTo({
						    url:'/pages/pay/monthly-card?id=0&state=1&from='+this.from
						});
					};
				}
			}
		}
	}
</script>

<style lang="scss" scoped>
	.list{
		padding:24rpx;
	}
	.home-float {
		position: fixed;
		z-index: 99;
		bottom: 100rpx;
		right: 50rpx;
	}
	.list-image{
		width:100%;
		height:220rpx;
		display: block;
	}
	.item{
		margin-bottom: 20rpx;
	}
</style>

